package com.rownext.kernel.logging.impl
{
	import com.rownext.kernel.logging.ILogger;
	import com.rownext.kernel.logging.LogLevel;
	
	import flexunit.framework.TestCase;	

	public class LoggerTest extends TestCase
	{
		public function testIsXXXEnabled():void
		{
			var loggerName:String = "dsad";
			var logger:ILogger = new Logger(loggerName, LogLevel.INFO);
			
			assertTrue(logger.isErrorEnabled());
			assertTrue(logger.isFatalEnabled());
			assertTrue(logger.isInfoEnabled());
			assertTrue(logger.isWarnEnabled());
			assertTrue(!logger.isTraceEnabled());
			assertTrue(logger.isDebugEnabled());
		}

		public function testLogEventDispatch():void
		{
			_logger = new Logger("test", LogLevel.INFO);
			_logger.addEventListener(LogEvent.LOG, addAsync(onLog, 10));
			
			_logger.trace("trace");
			_logger.debug("debug");
			_logger.info("info");
			_logger.error("error");
			_logger.warn("warn");
			_logger.fatal("fatal");
		}		

		private function onLog( e:LogEvent ):void
		{
			assertTrue(e.target === _logger);
			assertTrue(e.type == LogEvent.LOG);
			assertTrue(e.level != LogLevel.TRACE);
			assertTrue(e.level != LogLevel.DEBUG);
		}

		public function testConstructor():void
		{
			TestCase(8);
			var loggerName:String = "dsad";
			var logger:ILogger = new Logger(loggerName, LogLevel.INFO);
			assertEquals(logger.name, loggerName);
			assertTrue(logger.level === LogLevel.INFO);
			
			logger = new Logger(loggerName);	
			// 默认级别为 LogLevel.TRACE
			try
			{
				logger = new Logger("");
				logger = new Logger(null);
			}
			catch( err:ArgumentError )
			{
				assertEquals(err.message, "Invalid argument.");
			}
		}

		private var _logger:ILogger;
	}
}